package com.example.jinzproduct.controller.feign;

import com.example.commons.entity.UserDO;
import com.example.commons.entity.UserRoleDO;
import com.example.commons.utils.JWTUtil;
import com.example.jinzproduct.server.UserRoleService;
import com.example.jinzproduct.server.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author mengzhichao
 * @create 2022-09-09-10:24
 */
@RestController
@RequestMapping("/jinZhiIndex/UserFeignController")
public class UserFeignController {

    @Resource
    private UserRoleService userRoleService;

    @Autowired
    private UserService userService;

    /**
     * 用于获取用户角色信息
     */
    @PostMapping("/getUserId")
    public List<Long> listRoleId(@RequestBody String userId){
       // System.out.println("接收到参数------------------------------------"+userId);
        return userRoleService.listRoleId(Long.valueOf(userId));
    }

    /**
     * 修改用户信息
     */
    @PostMapping("/userUpdateById")
    public Boolean userUpdateById(@RequestBody UserDO userDO){
      //  System.out.println("接收到参数------------------------------------"+userDO);
        boolean b = userService.updateById(userDO);
        return b;
    }

    //获取token获取用户信息
    @PostMapping("/getUser")
    public UserDO getUser () {
      //  System.out.println("进入获取用户信息接口------------------------------------");
        UserDO user = JWTUtil.getUser(); //获取已登录用户信息
        return user;
    }

    @GetMapping("/findByKv")
    public List<UserRoleDO> findByKv(Object... params) {
        return userRoleService.findByKv(params);
    }

    //根据id获取用户信息
    @PostMapping("/getUserById")
    public UserDO getUserById(@RequestBody Long userid) {
       // System.out.println("接收到参数------------------------------------"+userid);
        //查询数据库根据用户id获取用户数据
        UserDO member = userService.getById(userid);
        return member;
    }



}
